<template>
  <div></div>
</template>
<script setup>
// 计算利息
import moment from "moment";

// startTime: 借钱时间
// endTime: 还钱时间
// rate: 年利率
// money: 借钱金额
const rate = 0.062;
const computeInterest = (startTime, endTime, money) => {
  const startTimeVlaue = moment(startTime, "YYYY-MM-DD").valueOf();
  const endTimeVlaue = moment(endTime, "YYYY-MM-DD").valueOf();
  const timeDiff = endTimeVlaue - startTimeVlaue;
  const days = timeDiff / (1000 * 60 * 60 * 24);
  const year = (days / 365).toFixed(4);
  const interest = (money * rate * year).toFixed(2);
  console.log(`按${moment(startTime).format("YYYY/MM/DD")}借的，借款期限${year}年，利息约为${interest}`);
  
  return interest;
};

const borrowList = [
  {
    time: "2016-11-04",
    money: 5000,
  },
  {
    time: "2016-11-30",
    money: 50000,
  },
  {
    time: "2019-01-14",
    money: 50000,
  },
];

const paybackList = [
  {
    time: "2017-10-26",
    borrowTime: borrowList[0],
    money: 5000,
  },
  {
    time: "2017-10-26",
    borrowTime: borrowList[1],
    money: 25000,
  },
  {
    time: "2018-08-27",
    borrowTime: borrowList[1],
    money: 2066.4,
  },
  {
    time: "2019-05-18",
    borrowTime: borrowList[1],
    money: 5000,
  },
  {
    time: "2020-04-02",
    borrowTime: borrowList[1],
    money: 20000,
  },
];
// computeInterest("2016-11-04", "2018-08-26", 5000);
// paybackList.forEach((el)=>{

// })

// computeInterest('2024-04-10',"2025-07-31", 1477.71);
// computeInterest('2016-11-30',"2017-10-26", 30000);
// computeInterest('2023-09-03',"2025-07-31", 4316.96);
computeInterest('2024-04-10',"2025-07-31", 2268.02);

</script>
<style lang="scss" scoped></style>
